<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
// checks to see if password session is set
// if not redirects to ../admin/
if($_SESSION['loggedIn'] == 0 && !isset($adminPage)){
include('auth.inc.php');
}


if (isset($_POST['ud_updated'])) {
	// check to see if details have been completed
	if (empty($_POST['ud_user']) || empty($_POST['ud_pass']) || empty($_POST['ud_email'])) {
	$error = 1;

	// else change details
	} else {
	$sql = sprintf("UPDATE affiliSt_config SET value = %s WHERE name = 'adUsername'",
			quote_smart($_POST['ud_user']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	$sql = sprintf("UPDATE affiliSt_config SET value = %s WHERE name = 'adPassword'",
			quote_smart($_POST['ud_pass']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	$sql = sprintf("UPDATE affiliSt_config SET value = %s WHERE name = 'adEmail'",
			quote_smart($_POST['ud_email']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	
	// email details
	$emailaddress = $_POST['ud_email'];
	$subject = "Your AffiliStore Details Have Been Updated";
	$emailfrom = $_POST['ud_email'];
	$message .= "Username: $ud_user \n Password: $ud_pass \n Email: $ud_email \n";
	$runtime = (date("d M Y H:i"));
	$message .= "Time of the message: $runtime (server time zone)\n\n";
	mail($emailaddress, $subject, $message, "From: '$emailfrom'");
	}
}

$getUserDetails = mysql_query("SELECT * FROM affiliSt_config");
$userDetails = mysql_fetch_assoc($getUserDetails);

?>

<?php
// error report
if ($error == 1) {
echo '<fieldset><strong style="color:red">ERROR: Fields must not be empty</strong></fieldset>';
} else {
	if (isset($_POST['ud_updated'])) {
	echo '<fieldset><strong style="color:green">Details Updated</strong></fieldset>';
	}
}
?>


<fieldset>
<legend>Update Your Details</legend>
<form action="index.php?ad=ud" method="post" name="updateDetails">

<table cellpadding="4" cellspacing="0" border="0">
<?php do { ?>
<?php if ($userDetails['name'] == 'adUsername') { ?>
<tr>
<td>
<label for="udUser">Username:</label>
</td>
<td>
<input name="ud_user" type="text" id="udUser" class="adminInput" value="<?php echo $userDetails['value'];?>" />
</td>
</tr>
<?php } ?>
<?php if ($userDetails['name'] == 'adPassword') { ?>
<tr>
<td>
<label for="udPass">Password:</label>
</td>
<td>
<input name="ud_pass" type="password" id="udPass" class="adminInput" value="<?php echo $userDetails['value'];?>" />
</td>
</tr>
<?php } ?>
<?php if ($userDetails['name'] == 'adEmail') { ?>
<tr>
<td>
<label for="udEmail">Email:</label>
</td>
<td>
<input name="ud_email" type="text" id="udEmail" class="adminInput" value="<?php echo $userDetails['value'];?>" />
</td>
</tr>
<?php } ?>
<?php } while ($userDetails = mysql_fetch_assoc($getUserDetails)); ?>
</table>
<input type="hidden" name="ud_updated" value="yes" />
<input value="Update Your Details" type="submit" class="padSubmit" />
</form>
</fieldset>